@page "/Cluster"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.PageBase

<Card Title="@KubeService.CurrentContext()" Style="margin: 50px">
    <GridRow >
        <GridCol Span="10" Style="padding: 10px">
            <HTable >
                <HTableColumn Title=@L["Address"]>
                    <ColorfulTag>@KubeService.Client().BaseUri</ColorfulTag>
                </HTableColumn>
                <HTableColumn Title=@L["Context"]>
                    <ColorfulTag>@KubeService.CurrentContext()</ColorfulTag>
                </HTableColumn>
                @if (ServerInfo != null)
                {
                    <HTableColumn Title=@L["Version"]>
                        <ColorfulTag>@ServerInfo.GitVersion</ColorfulTag>
                        <ColorfulTag>@ServerInfo.Platform</ColorfulTag>
                    </HTableColumn>
                }

            </HTable>
        </GridCol>
        <GridCol Span="10" Style="padding: 10px">
            @if (ComponentStatus is { Count: > 0 })
            {
                <HTable >
                    @foreach (var status in ComponentStatus)
                    {
                        <HTableColumn Title="@status.Name()">
                            <ConditionsTagView Conditions="@(status.Conditions.Adapt<IList<V1Condition>>())"></ConditionsTagView>
                        </HTableColumn>
                    }
                </HTable>
            }
        </GridCol>
    </GridRow>
</Card>
<Card Title="@L["Usage"]" Style="margin: 50px">
    <ClusterUsage></ClusterUsage>
</Card>

<Tabs Style="margin: 50px" DefaultActiveKey="Status" Type="@TabType.Card" Size="@TabSize.Large">
    <TabPane Key="Status" Tab=@L["API Status"]>
        @if (ApiServicesList is { Count: > 0 })
        {
            <GridRow Class="grid-table">
                <GridCol Span="8">Name</GridCol>
                <GridCol Span="8">Status</GridCol>
            </GridRow>
            @foreach (var item in ApiServicesList)
            {
                <GridRow Class="grid-table grid-table-first-row">
                    <GridCol Span="8"> @item.Name()</GridCol>
                    <GridCol Span="8">
                        <ConditionsTagView Conditions="@(item.Status.Conditions.Adapt<IList<V1Condition>>())"></ConditionsTagView>
                    </GridCol>
                </GridRow>
            }
        }
    </TabPane>

    @if (AllMetrics != null)
    {
        <TabPane Key="k8sFeature" Tab=@L["Feature"]>
            @if (AllMetrics.Any(x => x.Name == "kubernetes_feature_enabled") is true)
            {
                <GridRow Class="grid-table">
                    <GridCol Span="8">Name</GridCol>
                    <GridCol Span="4">Stage</GridCol>
                    <GridCol Span="4">Status</GridCol>
                    <GridCol Span="4">AI</GridCol>

                </GridRow>
                var measurements = AllMetrics.FirstOrDefault(x => x.Name == "kubernetes_feature_enabled")?.Measurements;
                if (measurements is { Count: > 0 })
                {
                    foreach (var item in measurements)
                    {
                        <GridRow Class="grid-table grid-table-first-row">

                            <GridCol Span="8">
                                @item.Labels["name"]
                            </GridCol>
                            <GridCol Span="4">
                                @item.Labels["stage"]
                            </GridCol>
                            <GridCol Span="4">
                                @if (item is { Value: > 0 })
                                {
                                    <Tag Color="@PresetColor.Green.ToString()">@L["Enabled"]</Tag>
                                }
                                else
                                {
                                    <Tag Color="@PresetColor.Red.ToString()">@L["Disabled"]</Tag>
                                }
                            </GridCol>
                            <GridCol Span="4">
                                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Question"
                                        OnClick="@(() => OnAnyChatClick(item.Labels["name"]))">
                                </Button>
                            </GridCol>
                        </GridRow>
                    }
                }
            }
        </TabPane>
    }


</Tabs >
